package com.top.art.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.top.art.annotation.PermissionLimit;
import com.top.art.bo.StudioBO;
import com.top.art.bo.StudioExamineeBO;
import com.top.art.entity.ExamineeInfo;
import com.top.art.entity.StudioInfo;
import com.top.art.service.IExamineeInfoService;
import com.top.art.service.IStudioInfoService;
import com.top.art.vo.ProvinceVO;
import com.top.art.vo.ResVO;
import com.top.art.vo.StudioVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 画室信息表 前端控制器
 * </p>
 *
 * @author hjh
 * @since 2020-10-05
 */
@RestController
@RequestMapping("/studio")
public class StudioInfoController {

    @Autowired
    private IStudioInfoService studioInfoService;

    @Autowired
    private IExamineeInfoService examineeInfoService;


    @PostMapping("/save")
    @PermissionLimit(limit = false)
    public ResVO save(StudioInfo studioInfo, MultipartFile examineeFile) throws IOException {
        studioInfoService.saveData(studioInfo, examineeFile);
        return new ResVO<StudioInfo>(200, "ok");
    }

    @PostMapping(value = "/update")
    @PermissionLimit(limit = false)
    public ResVO update(@RequestBody StudioInfo studioInfo) {
        return new ResVO(studioInfoService.update(studioInfo));
    }

    @PostMapping("/listStudio")
    @PermissionLimit(limit = false)
    public ResVO listStudio(@RequestBody StudioBO bo) {
        IPage<StudioInfo> page = studioInfoService.page(bo);
        return new ResVO(page);
    }

    @GetMapping(value = "/queryStudio")
    @PermissionLimit(limit = false)
    public ResVO queryStudio(Integer id) {
        return new ResVO(studioInfoService.getOne(Wrappers.<StudioInfo>lambdaQuery().eq(StudioInfo::getId, id)));
    }

    @PostMapping("/operationActivity")
    @PermissionLimit(limit = false)
    public ResVO operationActivity(@RequestBody StudioBO bo) {
        return new ResVO(studioInfoService.operationActivity(bo));
    }

    @PostMapping("/queryOrupdateByCode")
    @PermissionLimit(limit = false)
    public ResVO queryOrupdateByCode(@RequestBody StudioBO bo) {
        StudioVo vo = studioInfoService.queryOrupdateByCode(bo);
        return new ResVO(vo);
    }

    @PostMapping("/queryCount")
    @PermissionLimit(limit = false)
    public ResVO queryCount(@RequestParam String studioCode) {
        return new ResVO(studioInfoService.queryCount(studioCode));
    }

    @GetMapping(value = "/queryProvince")
    @PermissionLimit(limit = false)
    public ResVO<List<ProvinceVO>> queryProvince() {
        return new ResVO<>(studioInfoService.queryProvince());
    }

    @GetMapping(value = "/deleteStudio/{id}")
    @PermissionLimit(limit = false)
    public ResVO deleteStudio(@PathVariable Integer id){
        return new ResVO(studioInfoService.deleteStudio(id));
    }

    @PostMapping("/countExaminationInfo")
    @PermissionLimit(limit = false)
    public ResVO countExaminationInfo(@RequestParam String provinceCode){
        return new ResVO(studioInfoService.countExaminationInfo(provinceCode));
    }


}